#include "inc.h"
#include "tokenizer.h"

static const char *tokenToString(int type);

int main()
{
    char input_buf[512];
    int index = 0;
    Token token;

    strncpy(input_buf, STMT_SELECT, strlen(STMT_SELECT) + 1);
    // strncpy(input_buf, STMT_UPDATE, strlen(STMT_UPDATE) + 1);
    // strncpy(input_buf, STMT_DELETE, strlen(STMT_DELETE) + 1);
    // strncpy(input_buf, STMT_INSERT, strlen(STMT_INSERT) + 1);

    while ((input_buf[0] != '.') && (token = getNextToken(input_buf, &index, NULL)).type != TOKEN_EOF)
        printf("type: %-10s, value: %s\n", tokenToString(token.type), token.value);

    return 0;
}

static const char *tokenToString(int type)
{
    switch (type) {
        case TOKEN_SELECT:      return "SELECT";
        case TOKEN_FROM:        return "FROM";
        case TOKEN_WHERE:       return "WHERE";
        case TOKEN_IDENTIFIER:  return "IDENTIFIER";
        case TOKEN_NUMBER:      return "NUMBER";
        case TOKEN_GREATER:     return "GREATER";
        case TOKEN_LESS:        return "LESS";
        case TOKEN_EQUAL:       return "EQUAL";
        case TOKEN_GE:          return "GE";
        case TOKEN_LE:          return "LE";
        case TOKEN_NE:          return "NE";
        case TOKEN_AND:         return "AND";
        case TOKEN_OR:          return "OR";
        case TOKEN_STRING:      return "STRING";
        case TOKEN_COMMA:       return "COMMA";
        case TOKEN_STAR:        return "STAR";
        case TOKEN_EOF:         return "EOF";
        case TOKEN_INSERT:      return "INSERT";
        case TOKEN_INTO:        return "INTO";
        case TOKEN_DELETE:      return "DELETE";
        case TOKEN_UPDATE:      return "UPDATE";
        case TOKEN_VALUES:      return "VALUES";
        case TOKEN_ASSIGN:      return "ASSIGN";
        case TOKEN_SET:         return "SET";
        case TOKEN_LP:          return "LP";
        case TOKEN_RP:          return "RP";
        case TOKEN_INVALID:     return "INVALID";
        default:                return "UNKNOWN";
    }
}